package xyz.wanwanwan.www.hrm.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.wanwanwan.www.hrm.dto.SMSCodeDto;
import xyz.wanwanwan.www.hrm.service.IVerifycodeService;
import xyz.wanwanwan.www.hrm.util.AjaxResult;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {
    @Autowired
    private IVerifycodeService verifycodeService;

    /**
     * 发送图片验证码
     * @param imageCodeKey
     * @return
     */
    @GetMapping("/imageCode/{imageCodeKey}")
    public AjaxResult getImageCode(@PathVariable("imageCodeKey") String imageCodeKey){
        try {
            return AjaxResult.me().setResultObj(verifycodeService.getImageCode(imageCodeKey));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("获取失败");
        }
    }
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody SMSCodeDto smsCodeDto){
        try {
            return verifycodeService.sendSmsCode(smsCodeDto);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("获取短信验证码失败！！！！");
        }
    }
}
